package com.bvbot.core.bot;

import static com.bvbot.core.Logger.log;

import java.io.IOException;

import com.bvbot.db.DbTool;

/**
 * Records prices in db
 * 
 * @author otexier
 * 
 */
public class PriceRecordingBot extends AbstractBot<SimpleBotConfig> {

	public PriceRecordingBot(SimpleBotConfig config) {
		super(config);
	}

	@Override
	public Decision computeDecision() {
		return Decision.NOTHING;
	}

	@Override
	protected void beforeRun() {
		log("Start of " + this + " with config  " + getConfig());
	}

	@Override
	protected void applyDecision(Decision decision) {
		// NOPE
	}

	public static void main(String[] args) throws Exception {
		DbTool.startDb();
		SimpleBotConfig conf = new SimpleBotConfig();
		PriceRecordingBot bot = new PriceRecordingBot(conf);
		bot.start();
	}

	@Override
	protected void newCurrentPriceExtracted(Prices currentPrice) {
		try {
			log("Put in db : " + currentPrice);
			currentPrice.toDb(DbTool.getConnection());
		} catch (IOException e) {
			log("Impossible to put " + currentPrice + " in db : "
					+ e.getMessage(), e);
		}
	}

	@Override
	protected void reinitState() {
		// nope
	}

}
